package com.ruoyi.project.para.teller.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.para.teller.domain.Teller;
import com.ruoyi.project.para.teller.service.ITellerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 柜员信息Controller
 *
 * @author ruoyi
 * @date 2020-03-31
 */
@Controller
@RequestMapping("/para/teller")
public class TellerController extends BaseController
{
    private String prefix = "para/teller";

    @Autowired
    private ITellerService tellerService;

    @RequiresPermissions("para:teller:view")
    @GetMapping()
    public String teller()
    {
        return prefix + "/teller";
    }

    /**
     * 查询柜员信息列表
     */
    @RequiresPermissions("para:teller:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Teller teller)
    {
        startPage();
        List<Teller> list = tellerService.list(new QueryWrapper<>(teller));
        return getDataTable(list);
    }

    /**
     * 导出柜员信息列表
     */
    @Log(title = "柜员信息", businessType = BusinessType.EXPORT)
    @RequiresPermissions("para:teller:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Teller teller)
    {
        List<Teller> list = tellerService.list(new QueryWrapper<>(teller));
        ExcelUtil<Teller> util = new ExcelUtil<Teller>(Teller.class);
        return util.exportExcel(list, "柜员信息");
    }

    /**
     * 新增柜员信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存柜员信息
     */
    @RequiresPermissions("para:teller:add")
    @Log(title = "柜员信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Teller teller)
    {
        return toAjax(tellerService.saveOrUpdate(teller));
    }

    /**
     * 修改柜员信息
     */
    @GetMapping("/edit/{tellerId}")
    public String edit(@PathVariable("tellerId") String tellerId, ModelMap mmap)
    {
        Teller teller = tellerService.getById(tellerId);
        mmap.put("teller", teller);
        return prefix + "/edit";
    }

    /**
     * 修改保存柜员信息
     */
    @RequiresPermissions("para:teller:edit")
    @Log(title = "柜员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Teller teller)
    {
        return toAjax(tellerService.saveOrUpdate(teller));
    }

    /**
     * 删除柜员信息
     */
    @RequiresPermissions("para:teller:remove")
    @Log(title = "柜员信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tellerService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
